﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;

namespace DDD4Fun.State
{
    public class HasQuarterState : IState
    {
        Random randomWinner = new Random(0);
        MyStateMachine machine;

        public HasQuarterState(MyStateMachine machine)
        {
            this.machine = machine;
        }

        #region IState Members

        public void InsertQuarter()
        {
            Console.WriteLine("你投过币了");
        }

        public void EjectQuarter()
        {
            Console.WriteLine("成功退币");
            machine.SetState(machine.GetNoQuarterState());
        }

        public void TurnCrank()
        {
            Console.WriteLine("成功转动曲柄");
            int winner = randomWinner.Next(5);
            if (winner == 1 && machine.GetCount() > 0)
            {
                machine.SetState(machine.GetWinnerState());
            }
            else
            {
                machine.SetState(machine.GetSoldState());
            }
        }

        public void Dispense()
        {
            Console.WriteLine("不是发放糖果的时候");
        }

        #endregion
    }
}
